package org.newcih.dao;

import org.aspectj.weaver.ast.Or;
import org.newcih.domain.Order;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface IOrderDao extends PagingAndSortingRepository<Order, String>, JpaSpecificationExecutor<Order> {

    @Query("FROM Order WHERE id=:id")
    Order findByQuery(@Param("id") String id);

    Order findById(String id);

    Order findByOrderNumber(Integer number);

    @Modifying
    @Query("DELETE FROM Order WHERE id = :id")
    void deleteByQuery(@Param("id") String id);

    List<Order> findAll(Specification<Order> specification);
}
